package b3.model
{
	import b3.net.*;
	import b3.util.*;
	
	public class Guinness extends Model
	{
		public var worldRecords:Object;
		public var personalRecords:Object;
		
		public function Guinness()
		{
			super();
		}
		
		//加载世界纪录
		public function getWorldRecords(force:Boolean = false):void
		{
			var pm:PlayerManager = PlayerManager.getInstance();
			var serverRequest:ServerRequest = new ServerRequest(ServerEvent.GET_WORLD_RECORDS, {openid:pm.openid, openkey:pm.openkey, pf:pm.pf});
			serverRequest.setHandleFunc(handleGetWorldRecords);
			serverRequest.post(force);
		}
		
		private function handleGetWorldRecords(data:Object):void
		{
			var worldRecordData:Object = data['worldRecord'];
			worldRecords = new Object();
			for (var recordIndexStr:String in worldRecordData)
			{
				var recordInfo:RecordInfo = new RecordInfo();
				recordInfo.loadbyObject(worldRecordData[recordIndexStr]);
				worldRecords[recordIndexStr] = recordInfo;
			}
			var personalRecordData:Object = data['personalRecord'];
			personalRecords = new Object();
			for (recordIndexStr in personalRecordData)
			{
				recordInfo = new RecordInfo();
				recordInfo.loadbyObject(personalRecordData[recordIndexStr]);
				personalRecords[recordIndexStr] = recordInfo;
			}
			dispatchEvent(new ModelEvent(ModelEvent.GET_WORLD_RECORDS));
		}
		
	}
}